package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.viewpager.widget.PagerAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.util.Constant;

import java.util.ArrayList;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/9 16:25
 * description:
 */
public class UserCardVpAdapter extends PagerAdapter {

    private ArrayList<View> views = new ArrayList<>();
    private Context context;

    public UserCardVpAdapter(Context mContext) {
        context = mContext;
        View view = LayoutInflater.from(context).inflate(R.layout.user_vp_view, null, false);
        views.add(view);
        views.add(view);
        views.add(view);
    }
    @Override
    public int getCount() {
        L.e(Constant.TAG,"--getCount");
        return null == views ? 0 : views.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {

        L.e(Constant.TAG,"----isViewFromObject");
        return view == views.get((int)Integer.parseInt(object.toString()));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        View view1 = views.get(position);
        container.addView(view1);

        L.e(Constant.TAG,"--instantiateItem++container:" + container.getChildCount() + "++position:" + position);

        return position;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(views.get(position));
    }


}
